﻿using System.Runtime.Serialization;
using SmartMD.DataModel;
using System;

namespace SmartMD.DataModel.Entity
{
    [DataContract(Name = "SysDicItem", Namespace = "")]
    public class DictionaryItem : BusinessEntity
    {
        private string code;
        /// <summary>
        /// 字典项CODE
        /// </summary>
        [DataMember(Name = "code", EmitDefaultValue = false)]
        public string Code
        {
            get { return code; }
            set { code = value; OnPropertyChanged("Code"); }
        }

        private string dictTypeId;
        /// <summary>
        /// 父字典项ID
        /// </summary>
        [DataMember(Name = "dictTypeId", EmitDefaultValue = false)]
        public string DictTypeId
        {
            get { return dictTypeId; }
            set { dictTypeId = value; OnPropertyChanged("DictTypeId"); }
        }

        private string parentId;
        /// <summary>
        /// 父字典项ID
        /// </summary>
        [DataMember(Name = "fatherid", EmitDefaultValue = false)]
        public string ParentId
        {
            get { return parentId; }
            set { parentId = value; OnPropertyChanged("ParentId"); }
        }

        private string parentName;
        /// <summary>
        /// 父字典项名称
        /// </summary>
        public string ParentName
        {
            get { return parentName; }
            set { parentName = value; OnPropertyChanged("ParentName"); }
        }

        private string order;
        /// <summary>
        /// 字典项序号
        /// </summary>
        [DataMember(Name = "orderno", EmitDefaultValue = false)]
        public string Order
        {
            get { return order; }
            set { order = value; OnPropertyChanged("Order"); }
        }

        private DateTime createDate;
        /// <summary>
        /// 字典项创建日期
        /// </summary>
        [DataMember(Name = "createDate", EmitDefaultValue = false)]
        public DateTime  CreateDate
        {
            get { return createDate; }
            set { createDate = value; OnPropertyChanged("CreateDate"); }
        }

        private string isValid;
        /// <summary>
        /// 字典项是否可用
        /// </summary>
        [DataMember(Name = "isvalid", EmitDefaultValue = false)]
        public string IsValid
        {
            get
            {
                return isValid;
            }
            set { isValid = value; OnPropertyChanged("IsValid"); }
        }

        private bool isUsed;
        /// <summary>
        /// 字典项是否可用界面辅助属性
        /// </summary>
        public bool IsUsed
        {
            get
            {
                if (isValid == "1")
                {
                    isUsed = true;
                }
                else
                {
                    isUsed = false;
                }

                return isUsed;
            }
            set
            {
                if (isUsed != value)
                {
                    if (value)
                    {
                        isValid = "1";
                    }
                    else
                    {
                        isValid = "0";
                    }
                    isUsed = value;
                    OnPropertyChanged("IsUsed");
                }
            }
        }

        private DictionaryType dictionaryType;
        /// <summary>
        /// 字典项所属字典类别
        /// </summary>
        [DataMember(Name = "sysdictype", EmitDefaultValue = false)]
        public DictionaryType DictionaryType
        {
            get { return dictionaryType; }
            set { dictionaryType = value; OnPropertyChanged("DictionaryType"); }
        }

        public override string ToString()
        {
            return this.Name;
        }

        public override void setValue(string key, Object value)
        {
            if (value is System.DBNull)
                return;
            switch (key.ToLower())
            {
                case "dictid":
                    this.Id = (string)value;
                    break;
                case "dictypeid":
                    this.DictTypeId = (string)value;
                    break;
                case "name":
                    this.Name = (string)value;
                    break;
                case "code":
                    this.Code = (string)value;
                    break;
                case "fatherid":
                    this.parentId = (string)value;
                    break;
                case "orderno":
                    this.order = (string)value;
                    break;
                case "isvalid":
                    this.IsValid = (string)value;
                    break;
                case "createdate":
                    this.CreateDate = (DateTime)value;
                    break;
                default:
                    break;
            }
        }
    }
}
